import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

public class LoadedModificators extends LoadedSettings
{
	HashMap<Integer, Modifier> modifiers;
	static LoadedModificators rInstance;
	
	public HashMap<Integer, Modifier> getModifiers()
	{
		return modifiers;
	}

	static public LoadedModificators getInstance(String file)
	{
		if(rInstance == null)
		{
			rInstance = new LoadedModificators(file);
		}
		return rInstance;
	}
	
	static public LoadedModificators getInstance()
	{
		if(rInstance == null)
		{
			rInstance = new LoadedModificators(defaultModificatorsFilename);
		}
		return rInstance;
	}
	
	LoadedModificators(String file)
	{
		super(file);
		modifiers = new HashMap<Integer, Modifier>();
		loadModificators();
	}
	
	void loadModificators()
	{
		ArrayList<String> lines = load();
		int i=0;
		for (String line : lines) 
		{
			String[] description = line.split(SPLITTER);
			/*
			 * description[0] == constantModifier
			 * description[1] == sourceAttributeMultipilier
			 * description[2] == targetAttributeMultipilier
			 * description[3] == sourceAttribute.name
			 * description[4] == targetAttribute.name
			 * description[5] == modyfiingAttribute.name
			 */

			Attribute[] attribs = new Attribute[3];
			for (int k=0;k<3;++k)
			{
				attribs[k] = new Attribute(description[3+k], 0, false);
				int index = LoadedAttributes.getInstance().attributes.indexOf(attribs[k]);
				if(index == -1)
				{
					//TODO: throw bad line
				}
				attribs[k] = LoadedAttributes.getInstance().attributes.get(index);
			}
			modifiers.put(i, new Modifier(
					Integer.parseInt(description[0]),
					Double.parseDouble(description[1]),
					Double.parseDouble(description[2]),
					attribs[0],
					attribs[1],
					attribs[2]));
			++i;
		}
		System.err.println("LOADED MODIFIERS\n========================================");
		Collection<Modifier> col =  modifiers.values();
		for (Iterator iterator = col.iterator(); iterator.hasNext(); ) 
		{
			System.err.println(((Modifier)iterator.next()).toString());
			
		}
	}
}